
function orgnizerQuizStatus(module_name){

    var tabletools = new TableTools();

    var testgroup_info;
    $.ajax({
        type: "POST",
        url: module_name+"/Orgnizer/getQuizTitleList",
        dataType: "json",
        async: false,
        success: function (data) {
            console.log(data);
            if (data.code == -1){
                $("#quiz-result-li").hide();
                alert("还没有组织过测试，先组织一个测试！");

            }
            else{
                testgroup_info = data;
                var htmls = [];

                for(var i = 0; i <Object.keys(data).length; i++){
                    htmls.push('<option>'+data[i].title+'</option>');
                   // console.log(JSON.parse(data[i].quiz_list));
                    $("#quiz_title_select").html(htmls.join(''));
                }

                loadGroupInfo(0);
                loadQuizStatus($("#quiz_title_select").val());
                WarnValue_new();
            }



        }, error: function (jqXHR) {
            alert("读取测试组标题failed" + jqXHR.status);
        }
    });


    function loadGroupInfo(index_id)
    {

        $(document).off('click', '#delete_grouptest_btn');

        var group_htmls = [];

        var i = index_id;
        var data = testgroup_info;
        var quiz_list_obj = JSON.parse(data[i].quiz_list);

        for(var k = 0; k < Object.keys(quiz_list_obj).length; k++){
            var group_link = module_name+'/Orgnizer/show_groupReport/quiz_name/'+quiz_list_obj[k]+'/quiz_grouptitle/'+data[i].title;
            group_htmls.push('<li> <a href="'+group_link+'" target ="_blank">显示'+quiz_list_obj[k]+'集体报告</a> </li>');
        }


        $("#groupreport_list").html(group_htmls.join(''));


        $(document).on('click', '#delete_grouptest_btn', function(){

            $.ajax({
                type: "GET",
                url:module_name+'/Orgnizer/deleteGroupTest/grouptest_id/'+data[i].testgroup_id,
                dataType: "json",
                async: false,

                success: function (data) {
                    alert(data.msg);
                    location.reload();

                }, error: function (jqXHR) {
                    alert("删除组failed" + jqXHR.status);
                }
            });
        });





    }

    function WarnValue_new()
    {

        var warnval;
        $(document).off('click', '#commit-warnvalue');
        $(document).off('change', '.value_area');

        $.ajax({
            type: "GET",
            //url:"/Quiz/quiz/getWarnValue/oid/8/quiz_grouptitle/test",
            url:module_name+"/Orgnizer/getWarnValue/quiz_grouptitle/" +$("#quiz_title_select").val() ,
            dataType: "json",
            async:false,
            success: function (data) {
                warnval = data;
            }, error: function (jqXHR) {
                alert("加载预警值列表failed：" + jqXHR.status);
            }
        });

        var option_list = warnval.quiz_list;
        console.log(option_list);

        var htmls = [];
        for (var i = 0; i < Object.keys(option_list).length; i++){
            htmls.push('<option>'+option_list[i]+'</option>');
        }
        $("#warnvalue_select").html(htmls.join(''));

        $("#warnvalue_select").change(function(){
            pushValue($(this).val());
        });

        pushValue($("#warnvalue_select").val());

        $(document).on('change', '.value_area',function(){
            i = 0;
            var quiz_name = $("#warnvalue_select").val();

            var warnvalue = warnval.warnvalue_list[quiz_name];
            $("#warn-set-list").find('tr').each(function(){

                warnvalue[i].warn_value = $(this).find('td').eq(2).find('input').val();
                warnvalue[i++].warn_select = $(this).find('td').eq(1).find('select').get(0).selectedIndex;
            });

            //console.log(warnvalue);

            warnval.warnvalue_list[quiz_name] = warnvalue;

           // console.log(warnval.warnvalue_list);
            console.log(warnval);

        } );

        $(document).on('click', '#commit-warnvalue', function(e){
        e.stopPropagation();
        alert("开始提交");

        var json = {};

        for (var k in warnval.quiz_list){
            var rownum = 0;
            var quiz_name  = warnval.quiz_list[k];
            var val = warnval.warnvalue_list[quiz_name];
            json[quiz_name] = {};
            for (var i in val){
                var rowobj = {};
                rowobj[val[i].element_label] =  val[i].warn_value;
                rowobj.select =  val[i].warn_select;
                json[quiz_name][rownum++] = rowobj
            }
        }
        console.log(json);
        json = JSON.stringify(json);
        console.log(json);

        $.ajax({
            type: "POST",
            //url: "/Quiz/quiz/setWarnValue/oid/8/quiztitle/test",
            url:module_name+"/Orgnizer/setWarnValue/quiz_grouptitle/" +$("#quiz_title_select").val() ,
            dataType: "json",
            async: false,
            data:{
                jsondata: json
            },
            success: function (data) {
                alert(data.msg);
                pushValue($("#warnvalue_select").val());

            }, error: function (jqXHR) {
                alert("failed" + jqXHR.status);
            }
        });
    });

       // $("#commit-warnvalue").click();

        function pushValue(quiz_name)
        {
            var htmls = [];
            var warnvalue = warnval.warnvalue_list[quiz_name];

            for (i = 0; i < Object.keys(warnvalue).length; i++){
                htmls.push("<tr><td>"+warnvalue[i].element_name+"</td>");
                htmls.push("<td><select class='value_area'> <option>小于</option> <option>大于</option> </select></td>");
                htmls.push('<td><input type="number" class="value_area" id="'+warnvalue[i].element_label+'"></td></tr>');
            }

            $("#warn-set-list").html(htmls.join(''));

            i = 0;
            $("#warn-set-list").find('tr').each(function(){
                $input = $(this).find('td').eq(2).find('input');
                $input.val(warnvalue[i].warn_value);
                $select = $(this).find('td').eq(1).find('select');
                $select.get(0).selectedIndex= warnvalue[i].warn_select;
                i++;
            });
        }

    }


    $("#quiz_title_select").change(function(){//更改标题后的选择事件
        loadQuizStatus($("#quiz_title_select").val());
        WarnValue_new();
        loadGroupInfo($("#quiz_title_select").get(0).selectedIndex);
    });


    function loadQuizStatus(quiztitle)
    {
        function columns(){//表格列信息
            return [
                {
                    field: 'state',
                    checkbox: true
                },
                {
                    field:'username',
                    title:'用户名'

                },{
                    field:'email',
                    title:'邮箱'

                },{
                    field:'class',
                    title:'分组信息'
                },
                {
                    field:'quiz_list_name',
                    title:'被测问卷'
                },
                {
                    field:'timestamp',
                    title:'开始时间'
                },
                {
                    title:'操作',
                    formatter:function(){
                        return '<a class="btn btn-success btn-sm">查看详细</a>'
                    }
                }];
        }

        function QueryParams(para){//返回选定班级信息的人员信息查询json数组
            var querydata = {
                quiztitle:quiztitle
            };
            return querydata;
        }

        function onClickRow(row) {//点击用户信息行弹出修改用户信息对话框

            $.ajax({
                type: "POST",
                url: module_name+"/Orgnizer/showQuizStatusDetail",
                dataType: "json",
                async: false,
                data: {
                    quiz_list_json: row.quiz_list,
                    uid: row.uid
                },
                success: function (data) {
                    var htmls = [];
                    for (var i = 0; i < Object.keys(data).length; i++){

                        var progress_htmls = ['<td><div class="progress progress-lg">'+
                        '<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: '+data[i].percent+'%" id="qpercent">'+
                        '<span class="sr-only">40% Complete (success)</span>'+
                        ' </div> </div></td>'];

                        htmls.push("<tr><td>"+data[i].quiz_title+"</td>");
                        htmls.push(progress_htmls);

                        if (data[i].percent >= 100){
                            htmls.push('<td> <a class="btn btn-primary btn-sm" target="_blank" href='+module_name+'/Orgnizer/show_userReport/uid/'+row.uid+'/quiz_id/'+data[i].quiz_id+'>查看报告</a> <a class="btn btn-primary btn-sm" target="_blank" href="'+module_name+'/Orgnizer/downloadUserReportPdf/uid/'+row.uid+'/quiz_id/'+data[i].quiz_id+'">下载pdf</a> </td>');
                        }
                        else
                            htmls.push('<td> <a class="btn btn-primary btn-sm disabled" >查看报告</a> <a class="btn btn-primary btn-sm disabled">下载pdf</a> </td>');

                    }

                    $("#quiz_detail_modal_tbody").html(htmls.join(''));
                    $("#row_userquiz_info").modal('show');

                }, error: function (jqXHR) {
                    alert("读取问卷详细进度failed" + jqXHR.status);
                }

            });

        }

        tabletools.bstable("quiz_users_resulttable", module_name+"/Orgnizer/showQuizStatus",columns(), QueryParams, onClickRow);


        //读取集体报告信息
    }



}

$(document).ready(function() {




});